﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.DataAnnotations;

namespace Domain.Test
{
    [TestClass]
    public class UnitTestDataAnnotationsValidator
    {
        [TestMethod]
        public void WhenValidatingCustomerWithMissingFirstName_ResultShouldContainOneValidationErrorMessage()
        {
            //using data annotations for validation outside of a UI framework, like ASP.NET MVC .

            Customer cut = new Customer();



          
            var results = new List<ValidationResult>();

            // a static customer Validator class to execute the validation rules
            var isValid = DataAnnotationsValidator.TryValidate(cut, out results);

            Assert.IsFalse(isValid);
            Assert.IsNotNull(results);
            Assert.IsTrue(results.Count == 1);

            if (!isValid)
            {
                foreach (var validationResult in results)
                {
                    Console.WriteLine(validationResult.ErrorMessage);
                }
            }

        }


        [TestMethod]
        public void WhenValidatingInvalidAddress_ResultShouldContainOneMessage()
        {
            Address cut = new Address();

            List<ValidationResult> resultToList = new List<ValidationResult>();
            var isValid = DataAnnotationsValidator.TryValidate(cut, out resultToList);

      
            Assert.IsFalse(isValid);
            Assert.IsNotNull(resultToList);
            Assert.IsTrue(resultToList.Count == 1);


            foreach (var validationResult in resultToList)
            {
                Console.WriteLine(validationResult.ErrorMessage);
            }

        }
    }
}
